package com.junzhiit.nengji.cms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ShopDeliveryService;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.ShopDeliveryAddVO;
import com.junzhiit.nengji.model.ShopDelivery;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/shop/delivery")
public class ShopDeliveryController extends BaseController {
	
	@Autowired
	private ShopDeliveryService shopDeliveryService;
	
	@ApiOperation(value = "获取所有的店铺配送信息")
	@RequestMapping( method = RequestMethod.GET)
	public ResultVO findAllByShopId(String sessionId){
		AssertUtil.notNull(sessionId, "sessionId is required.");
		return shopDeliveryService.findAllByShopId(sessionId);
	}
	
	@ApiOperation(value = "获取该配送ID的店铺配送信息")
	@RequestMapping( value="/{shopDeliveryId}", method = RequestMethod.GET)
	public ResultVO getByShopId(@PathVariable String shopDeliveryId){
		AssertUtil.notNull(shopDeliveryId, "shopDeliveryId is required.");
		return shopDeliveryService.getByShopId(shopDeliveryId);
	}
	
	@ApiOperation(value = "删除该配送ID的店铺配送信息")
	@RequestMapping(method = RequestMethod.DELETE)
	public ResultVO delete(String shopDeliveryId){
		AssertUtil.notNull(shopDeliveryId, "shopDeliveryId is required.");
		return shopDeliveryService.delete(shopDeliveryId);
	}
	
	@ApiOperation(value = "修改该配送ID的店铺配送信息")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(ShopDelivery shopDelivery,String sessionId){
		AssertUtil.notNull(shopDelivery.getId(), "shopDeliveryId is required.");
		return shopDeliveryService.update(shopDelivery,sessionId);
	}
	
	@ApiOperation(value = "添加配送信息")
	@RequestMapping( method = RequestMethod.POST)
	public ResultVO insert(ShopDeliveryAddVO vo){
		AssertUtil.notNull(vo.getMinDelivery(), "minDelivery is required.");
		AssertUtil.notNull(vo.getMaxDelivery(), "maxDelivery is required.");
		AssertUtil.notNull(vo.getSessionId(), "sessionId is required.");
		return shopDeliveryService.insert(vo);
	}
	
	@ApiOperation(value = "配送距离、配送工具下符合的最小配送距离")
	@RequestMapping(value="/adapt", method = RequestMethod.GET)
	public ResultVO adapt(String sessionId,Integer type,Integer vehicle){
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notNull(type, "type is required.");
		AssertUtil.notNull(vehicle, "vehicle is required.");
		return shopDeliveryService.adapt(sessionId,type,vehicle);
	}
	
}
